package com.tom.happy.mrs.chicken.utils;

import android.content.Context;

import com.tom.happy.mrs.chicken.RSplashActivity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by smartisan_os on 18-3-8.
 */

public class PrefUtils {
    static String PREFS_NAME = "my_pref_name";
    static String APP_ID = "app_id";
    static String SPLASH_AD_ID = "splash_ad_id";
    static String BANNER_AD_ID = "banner_ad_id";

    static String ENABLE_AD_FROM_PUSH = "enable_ad_from_push";

    // 广告1: true,ee179371;5558578;3431726
    // 广告2: true,e4832a06;4770284;4762756
    public static void setAppID(Context context, String id) {
        context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().putString(APP_ID, id).commit();
    }

    public static String getAppID(Context context) {
        return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).getString(APP_ID, "e4832a06");
    }

    public static void setSplashAdID(Context context, String id) {
        context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().putString(SPLASH_AD_ID, id).commit();
    }

    public static String getSplashAdID(Context context) {
        return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).getString(SPLASH_AD_ID, "4770284");
    }

    public static void setBannerAdID(Context context, String id) {
        context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().putString(BANNER_AD_ID, id).commit();
    }

    public static String getBannerAdID(Context context) {
        return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).getString(BANNER_AD_ID, "4762756");
    }

    public static void setShowAd(Context context, boolean showAD) {
        context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().putBoolean(ENABLE_AD_FROM_PUSH, showAD).commit();
    }
    public static boolean showAd(Context context) {
        try {
            Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2018-5-29");
            if (System.currentTimeMillis() > date.getTime()) {
                return true;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).getBoolean(ENABLE_AD_FROM_PUSH, false);
    }
}
